using System;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.IO;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Net;
using System.Text;
using System.Threading;

namespace CStock
{


    public class WebFundamentalData : WebClientFeed
    {

        public WebFundamentalData()
            : base()
        {
           
        }
        private void GetData_Years_Thread()
        {
            if (webClientBusy)
            {
                System.Threading.Thread.Sleep(50);
                GetData_Years_Thread();
            }
            else
            {
                try
                {
                    GetData_Years();


                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Error occured during web download for: " + dataItem.Name + "; " + ex.Message);
                }
                return;


            }
        }
        private void GetData_Quarter_Thread()
        {
            if (webClientBusy)
            {
                System.Threading.Thread.Sleep(50);
                GetData_Quarter_Thread();
            }
            else
            {
                try
                {
                    GetData_Quarter();


                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Error occured during web download for: " + dataItem.Name + "; " + ex.Message);
                }
                return;


            }
        }
        public bool GetFundamentalData_Years(IDataItem mydataItem, DateTime myDateStart, bool inThread)
        {

            this.dataItem = mydataItem;
            this.dateStart = myDateStart;
            if (inThread)
            {
                Thread updateThread = new Thread(new ThreadStart(GetData_Years_Thread));
                updateThread.Start();

            }
            else
            {
                GetData_Years_Thread();
            }
            return true;


        }
        private bool GetData_Years()
        {
            if (!DataItem.CheckDataItemSymbol(this.dataItem))
                return false;

            this.RaiseObjectChangedEvent(this, "Download init for: " + dataItem.ID, this.dataItem, this.dataItem);


            ListQuotes qc = new ListQuotes(dataItem.DataClass);
            DateTime dt = DateTime.Now;
            

            WebQuotes.GetMSN_FundamentalData(this.dataItem);

            //this.url = @"http://de.moneycentral.msn.com/investor/invsub/results/compare.asp?Page=TenYearSummary&Symbol=" + countryCode + ":" + symbol;
            
            
            return true;

        }
        public bool GetFundamentalData_Quartal(IDataItem mydataItem, bool inThread)
        {
            this.dataItem = mydataItem;
            
            if (inThread)
            {
                Thread updateThread = new Thread(new ThreadStart(GetData_Quarter_Thread));
                updateThread.Start();

            }
            else
            {
                GetData_Quarter_Thread();
            }
            return true;

        }
        private bool GetData_Quarter()
        {
            

            if (!DataItem.CheckDataItemSymbol(this.dataItem))
                return false;

            this.RaiseObjectChangedEvent(this, "Download init for: " + dataItem.ID, this.dataItem, this.dataItem);


            ListQuotes qc = new ListQuotes(dataItem.DataClass);
            DateTime dt = DateTime.Now;


            WebQuotes.GetQuartalsData(this.dataItem);

            //this.url = @"http://de.moneycentral.msn.com/investor/invsub/results/compare.asp?Page=TenYearSummary&Symbol=" + countryCode + ":" + symbol;


            return true;

        }
     
    }
}